package api

import (
	"api-gateway/basic/config"
	__ "api-gateway/basic/proto"
	"api-gateway/handler/request"
	"api-gateway/handler/resp"
	"github.com/gin-gonic/gin"
)

// 清洁师添加
func AddCleaner(c *gin.Context) {
	var req request.AddCleanerReq
	if err := c.ShouldBind(&req); err != nil {
		resp.Error(c, 400, "参数有误", err.Error())
		return
	}

	addCleaner, err := config.HouseClient.AddCleaner(c, &__.AddCleanerReq{
		CustomerId: req.CustomerId,
		RealName:   req.RealName,
		Desc:       req.Desc,
		Address:    req.Address,
		ClassType:  req.ClassType,
	})
	if err != nil {
		resp.Error(c, 500, "服务端错误", err.Error())
		return
	}

	resp.Success(c, "清洁师添加成功", addCleaner)

}

// 清洁师列表
func GetCleanerList(c *gin.Context) {
	var req request.GetCleanerListReq
	if err := c.ShouldBind(&req); err != nil {
		resp.Error(c, 400, "参数有误", err.Error())
		return
	}

	cleanerList, err := config.HouseClient.GetCleanerList(c, &__.GetCleanerListReq{
		ClassType: req.ClassType,
	})
	if err != nil {
		resp.Error(c, 500, "服务端错误", err.Error())
		return
	}

	resp.Success(c, "清洁师列表展示成功", cleanerList)
}

// 认证
func AuthCleaner(c *gin.Context) {
	var req request.AuthCleanerReq
	if err := c.ShouldBind(&req); err != nil {
		resp.Error(c, 400, "参数有误", err.Error())
		return
	}

	authCleaner, err := config.HouseClient.AuthCleaner(c, &__.AuthCleanerReq{
		CleanerId: req.CleanerId,
		Image:     req.Image,
	})

	if err != nil {
		resp.Error(c, 500, "服务端错误", err.Error())
		return
	}

	resp.Success(c, "清洁师上传认证成功", authCleaner)
}

// 审核
func UpdateCheckStatus(c *gin.Context) {
	var req request.UpdateCheckStatusReq
	if err := c.ShouldBind(&req); err != nil {
		resp.Error(c, 400, "参数有误", err.Error())
		return
	}

	checkStatus, err := config.HouseClient.UpdateCheckStatus(c, &__.UpdateCheckStatusReq{
		CleanerId: req.CleanerId,
		Check:     req.Check,
	})

	if err != nil {
		resp.Error(c, 500, "服务端错误", err.Error())
		return
	}

	resp.Success(c, "更新审核状态成功", checkStatus)
}
